<template>
  <el-menu class="side-menu" :background-color="menuBackgroundColor" :text-color="menuTextColor" :active-text-color="activeTextColor" :default-active="activeName" :collapse="false">
    <el-menu-item index="Index">
      <template slot="title">
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </template>
    </el-menu-item>
    <el-submenu :index="item.name" v-for="(item, index) in menuList" :key="index">
      <template slot="title">
        <i :class="item.icon"></i>
        <span slot="title">{{ item.title }}</span>
      </template>
      <router-link :to="citem.path" v-for="(citem, cindex) in item.children" :key="cindex">
        <el-menu-item :index="citem.name" @click="selectMenu(citem)">
          <template slot="title">
            <i :class="citem.icon"></i>
            <span slot="title">{{ citem.title }}</span>
          </template>
        </el-menu-item>
      </router-link>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: 'SideMenu',
  data() {
    return {
      menuList: this.$store.state.menu.menuList,
      menuBackgroundColor: '#ffd1d1',
      menuTextColor: '#333',
      activeTextColor: '#fff'
    }
  },
  computed: {
    activeName() {
      return this.$store.state.menu.editableTabsValue
    }
  },
  components: {},
  methods: {
    selectMenu(menu) {
      let tabObj = {
        icon: menu.icon,
        title: menu.title,
        name: menu.name,
      }
      this.$store.commit('addTabs', tabObj)
    }
  }
}
</script>

<style scoped>
.side-menu {
  height: 100%;
}

.side-menu .el-menu-item,
.side-menu .el-submenu {
  font-size: 16px;
  font-weight: bold;
}

.side-menu .el-submenu__title {
  height: 50px;
  line-height: 50px;
}

.side-menu .el-menu-item__title,
.side-menu .el-submenu__title > i {
  margin-right: 10px;
}

.side-menu .el-menu-item__title:hover,
.side-menu .el-submenu__title:hover {
  color: #e74c3c;
}

.side-menu .el-menu-item__index,
.side-menu .el-submenu__index {
  color: #ccc;
}

.side-menu .el-submenu.is-opened > .el-submenu__title {
  color: #e74c3c;
}

.side-menu .el-menu-item.is-active,
.side-menu .el-submenu.is-active > .el-submenu__title {
  color: #fff;
  background-color: #e74c3c;
}

.side-menu .el-submenu.is-active > .el-submenu__title > i {
  color: #fff;
}

.side-menu .el-submenu.is-active > .el-menu {
  background-color: #f5b7b1;
}

a {
  text-decoration: none;
}
</style>
